<?php
if ( ! defined('BASEPATH')) exit('el acceso directo a esta página no esta permitido.');
class users_model extends ci_model
{
      public function __construct()
      {
        parent::__construct();  
        $this->load->database();
      }

    function checklogin($login)
     {
       $strquery = "select idusuario from usuarios where login = '". $login ."'";
       $query = $this->db->query($strquery);
       return $query -> num_rows() == 1?'{"result":"true"}':'{"result":"false"}';
     }
    
     function getservicios(){
         $session_data = $this->session->userdata('logged_in');
         $idempresa = $session_data['empresa'];
         $sql= "select ts.idservicio,ts.servicio from empresaservicio as es inner join tiposervicio as ts on es.idservicio = ts.idservicio where idempresa = " .$idempresa;
         $this->db->query($sql);
         $query = $this->db->query($sql);
         return $query->result();
     }
     
     function login($username, $password)
     {
       $strquery = "select u.idusuario, tu.tipousuario, u.nombrecompleto, u.login, u.pass, u.empresa, e.oauth_token, e.oauth_token_secret from usuarios as u inner join tipousuario as tu on tu.idtipo = u.tipousuario inner join empresas as e on u.empresa = e.idempresa  where u.login = '" .$username ."' and u.pass = '".$password ."'";
       $query = $this->db->query($strquery);
       return $query -> num_rows() == 1? $query->result(): false ;
     }
}
?>
